package com.sino.util;

public class EncryptUtil {
	public static final String key = "765";

	//����
	public static String jiaMi(String s, String key) {
		String str = "";
		int ch;
		if (key.length() == 0) {
			return s;
		} else if (!s.equals(null)) {
			for (int i = 0, j = 0; i < s.length(); i++, j++) {
				if (j > key.length() - 1) {
					j = j % key.length();
				}
				ch = s.codePointAt(i) + key.codePointAt(j);
				
				if (ch > 65535) {
					ch = ch % 65535;
				}
				str += (char) ch;
			}
		}
		return StringUtils.GetRandomChar(18)+str+StringUtils.GetRandomChar(15);

	}
	//����
	public static String jieMi(String s, String key) {
		s = s.substring(18, s.length()-15);
		String str = "";
		int ch;
		if (key.length() == 0) {
			return s;
		} else if (!s.equals(key)) {
			for (int i = 0, j = 0; i < s.length(); i++, j++) {
				if (j > key.length() - 1) {
					j = j % key.length();
				}
				ch = (s.codePointAt(i) + 65535 - key.codePointAt(j));
				if (ch > 65535) {
					ch = ch % 65535;
				}
				str += (char) ch;
			}
		}
		return str;
	}

	public static void main(String args[]) {
		String aa = EncryptUtil.jiaMi("chen", EncryptUtil.key);
		System.out.println(aa);
		System.out.print(EncryptUtil.jieMi(aa, EncryptUtil.key));
	}
}
